package net.roostertech.bta2dpfixer;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class StateChangeReceiver extends BroadcastReceiver {

	private final String LOGTAG = "BTFixer";

	@Override
	public void onReceive(Context context, Intent intent) {

		if (intent.getAction().equals(BluetoothDevice.ACTION_ACL_CONNECTED)) {
			BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
			Intent i = new Intent();
			i.setClassName(this.getClass().getPackage().getName(), BTFixerService.class.getName());
			i.setAction(BTFixerService.DEVICE_CONNECTED);
			i.putExtra(BluetoothDevice.EXTRA_DEVICE, device);
			Log.i(LOGTAG, "New connection is detected");
			context.getApplicationContext().startService(i);
		}
	}

}
